package dapps.web.monitor;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletResponseAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.security.springsecurity.SpringSecurityUtils;

import com.opensymphony.xwork2.ActionSupport;

import dapps.entity.monitor.Indicator;
import dapps.service.monitor.MonitorManager;

@SuppressWarnings("serial")
public class StaticsajaxAction extends ActionSupport implements
		ServletResponseAware {


	@Autowired
	private MonitorManager mManager;
	private HttpServletResponse response;

	public void setServletResponse(HttpServletResponse response) {
		this.response = response;     
	}
	//private HttpServletRequest request = Struts2Utils.getRequest();
	
	private Map<String, Integer> predivalues;
	private Map<String, Double> datavalues;
	private Map<String, Double> datalmvalues;
	private List<Indicator>  dataIndicatorvalues;
	private String reportDate;
	private	Long districtid;

	public String execute() throws Exception {
		//HttpServletRequest request = Struts2Utils.getRequest();
		String value="";
		Long udistrictid = SpringSecurityUtils.getCurrentUser().getDistrict().getId();
		if(udistrictid!=null&&udistrictid>0L){
			districtid = udistrictid;
		}
		if(districtid==null) districtid=0L;
		predivalues = mManager.getStaticsPredi(reportDate,0l,districtid);
		datavalues = mManager.getStaticsData(reportDate,0l,districtid);
		datalmvalues = mManager.getStaticsLastmonth(reportDate,0l,districtid);
		dataIndicatorvalues = mManager.getStaticsIndicators(reportDate,districtid);
		response.setContentType("text/xml; charset=utf-8");
		response.setHeader("Cache-Control", "no-cache");
		try {
			response.getWriter().write(value);
			response.getWriter().flush();
		} catch (IOException e) {			
		}
		return NONE;
	}



	public Map<String, Integer> getPredivalues() {
		return predivalues;
	}



	public List<Indicator> getDataIndicatorvalues() {
		return dataIndicatorvalues;
	}



	public void setDataIndicatorvalues(List<Indicator> dataIndicatorvalues) {
		this.dataIndicatorvalues = dataIndicatorvalues;
	}



	public void setPredivalues(Map<String, Integer> predivalues) {
		this.predivalues = predivalues;
	}



	public Map<String, Double> getDatavalues() {
		return datavalues;
	}



	public void setDatavalues(Map<String, Double> datavalues) {
		this.datavalues = datavalues;
	}



	public Map<String, Double> getDatalmvalues() {
		return datalmvalues;
	}



	public void setDatalmvalues(Map<String, Double> datalmvalues) {
		this.datalmvalues = datalmvalues;
	}


	public String getReportDate() {
		return reportDate;
	}

	public void setReportDate(String reportDate) {
		this.reportDate = reportDate;
	}



	

}
